/**
 * <p>Title: SysVersionVO.java</p>
 *
 * @Package org.apollo.maius.vo
 * <p>Description: 系统版本VO类</p>
 * @version V1.0
 * @since 2017年5月8日 上午10:46:26
 */
package com.synjones.zeus.model.version;

import java.io.Serializable;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * <p>
 * Description: 系统版本VO类
 * </p>
 *
 * @version V1.0
 */
@SuppressWarnings("serial")
public class SysVersionVO implements Serializable {
    private int id;
    private long listid; // flow-number
    private String resurl;
    private String pt;
    private String createTime;
    /**
     * 版本号第三位
     */
    private int tail;
    private int forceug;
    private String stamp; // compile-stamp
    private String alias; // version-alias
    private int majority;
    private int minority;
    private String schoolCode; // schoolCode in this layer
    //1生效0无效
    private int status;
    private String updateInfo;
    private int downs;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public int getDowns() {
        return downs;
    }

    public void setDowns(int downs) {
        this.downs = downs;
    }

    public static String getTemplate() {
        return template;
    }

    public static void setTemplate(String template) {
        SysVersionVO.template = template;
    }

    public static DateFormat getDf() {
        return df;
    }

    public static void setDf(DateFormat df) {
        SysVersionVO.df = df;
    }

    public static Pattern getPn() {
        return pn;
    }

    public static void setPn(Pattern pn) {
        SysVersionVO.pn = pn;
    }

    /**
     * @return flow-number
     */
    public long getListid() {
        return this.listid;
    }

    public void setListid(long listid) {
        this.listid = listid;
    }

    public String getResurl() {
        return this.resurl;
    }

    public void setResurl(String resurl) {
        this.resurl = resurl;
    }

    public String getPt() {
        return this.pt;
    }

    public void setPt(String pt) {
        this.pt = pt;
    }

    public String getCreateTime() {
        return this.createTime;
    }

    public void setCreateTime(String createTime) {
        this.createTime = createTime;
    }

    public int getTail() {
        return this.tail;
    }

    public void setTail(int tail) {
        this.tail = tail;
    }

    public int getForceug() {
        return this.forceug;
    }

    public void setForceug(int forceug) {
        this.forceug = forceug;
    }

    /**
     * @return compile-stamp
     */
    public String getStamp() {
        return this.stamp;
    }

    public void setStamp(String stamp) {
        this.stamp = stamp;
    }

    /**
     * @return version-alias
     */
    public String getAlias() {
        return this.alias;
    }

    public void setAlias(String alias) {
        this.alias = alias;
    }

    public int getMajority() {
        return this.majority;
    }

    public void setMajority(int majority) {
        this.majority = majority;
    }

    public int getMinority() {
        return this.minority;
    }

    public void setMinority(int minority) {
        this.minority = minority;
    }

    /**
     * @return schoolCode in this layer
     */
    public String getSchoolCode() {
        return this.schoolCode;
    }

    public void setSchoolCode(String schoolCode) {
        this.schoolCode = schoolCode;
    }

    public int getStatus() {
        return this.status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public String getUpdateInfo() {
        return updateInfo;
    }

    public void setUpdateInfo(String updateInfo) {
        this.updateInfo = updateInfo;
    }

    private static String template = "[listid:%s,resurl:%s,pt:%s,createTime:%s,tail:%s,forceug:%s,stamp:%s,alias:%s,majority:%s,minority:%s,schoolCode:%s,status:%s]";

    private static DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    @Override
    public String toString() {
        return String.format(template, listid, resurl, pt, createTime, tail, forceug, stamp, alias, majority, minority, schoolCode, status);
    }

    public SysVersionVO() {
    }

    public SysVersionVO(int major, int minor, int tail, String stamp) {
        this.majority = major;
        this.minority = minor;
        this.tail = tail;
        this.stamp = stamp;
    }

    private static Pattern pn = Pattern.compile("([\\d]+).([\\d]+).([\\d]+)-([\\d]+)");

    public SysVersionVO(String version) throws IllegalArgumentException {
        Matcher m = pn.matcher(version);
        if (m.matches()) {
            this.majority = Integer.parseInt(m.group(1));
            this.minority = Integer.parseInt(m.group(2));
            this.tail = Integer.parseInt(m.group(3));
            this.stamp = m.group(4);
        } else {
            throw new IllegalArgumentException("version must be in format of '([\\d]+).([\\d]+).([\\d]+)-([\\d]+)'");
        }
    }

    public String version() {
        return String.format("%s.%s.%s-%s", majority, minority, tail, stamp);
    }
    // //import org.springframework.beans.BeanUtils;
    // public SysVersionVO toVO(SysVersion ins)
    // {
    // if (ins == null)
    // return new SysVersionVO();
    // else
    // {
    // SysVersionVO vo = new SysVersionVO();
    // BeanUtils.copyProperties(ins, vo);
    // return vo;
    // }
    // }
    //
    // public SysVersion fromVO(SysVersionVO vo)
    // {
    // if (vo == null)
    // return new SysVersion();
    // else
    // {
    // SysVersion ins = new SysVersion();
    // BeanUtils.copyProperties(vo, ins);
    // return ins;
    // }
    // }
}
